" vim: ts=2 sw=2 et
" https://segmentfault.com/a/1190000003962806

set nocompatible
set encoding=utf-8
set nu
set rnu
set ruler
set autoindent
set noswapfile
set hls
set foldmethod=indent
set foldlevel=99
set clipboard=unnamed
set helplang=cn
set laststatus=2
" set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P

let plugin_list = [
			\ 'https://gitee.com/chenxinliang123/vim-plug',
			\ 'archerc/vim-colors-solarized',
			\ 'archerc/vim-airline',
			\ 'archerc/vim-leader-guide',
			\ 'archerc/vimcdoc',
			\ 'VundleVim/Vundle.vim',
			\ 'tmhedberg/SimpylFold',
			\ 'vim-scripts/indentpython.vim',
			\ 'scrooloose/syntastic',
			\ 'scrooloose/nerdtree',
			\ 'scrooloose/nerdcommenter',
			\ 'jistr/vim-nerdtree-tabs',
			\ 'kien/ctrlp.vim',
			\ 'nvie/vim-flake8',
			\ 'tpope/vim-fugitive',
			\ 'Lokaltog/powerline',
			\ 'Shougo/vimproc.vim',
			\ 'Shougo/vimshell.vim',
			\ 'Shougo/dein.vim',
			\ 'Shougo/unite.vim',
			\ 'Shougo/denite.nvim',
			\ 'Shougo/defx.nvim',
			\ 'Shougo/neomru.vim',
			\ 'Shougo/deoplete.nvim',
			\ 'Shougo/echodoc.vim',
			\ 'Shougo/context_filetype.vim',
			\ 'Shougo/unite-outline',
			\ 'Shougo/vimfiler.vim'
			\ ]
" 'fholgado/minibufexpl.vim',
" 'Shougo/deol.nvim',
"powerline: , {'rtp': 'powerline/bindings/vim/'}
" 'Valloric/YouCompleteMe',
" call SetupVundle(plugin_list)
"\ 'Shougo/deoppet.nvim',

let g:SimpylFold_docstring_preview = 1
let g:ycm_autoclose_preview_window_after_completion=1
let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree
" map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>

filetype plugin indent on
let python_highlight_all=1
syntax enable

set splitbelow
set splitright

nnoremap <C-s> :w<CR>
"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" nnoremap <C-v> <Esc>"+p

let mapleader = ','
nnoremap <Leader>e :VimFilerBufferDir -explorer<CR>
nnoremap <Leader>: :<C-F>
nnoremap <Leader>v :edit $VIM/vimrc<CR>
nnoremap <Leader>r :source $VIM/vimrc<CR>
nnoremap <Leader>i :PlugInstall<CR>
nnoremap <Leader>gs :Gstatus<CR>
nnoremap <C-/> :NERDComToggleComment<CR>
nnoremap <C-p> :CtrlPBuffer<CR>
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
nnoremap ]b   :bnext<CR>
nnoremap [b   :bprev<CR>

augroup filetype_python
  autocmd!
  au BufNewFile,BufRead *.py set 
        \ tabstop=4
        \ softtabstop=4
        \ shiftwidth=4
        \ textwidth=79
        \ expandtab
        \ autoindent
        \ fileformat=unix
augroup END
augroup filetype_html_css
  autocmd!
  au BufNewFile,BufRead *.js, *.html, *.css set
        \ tabstop=2
        \ softtabstop=2
        \ shiftwidth=2
augroup END
augroup filetype_vim
  autocmd!
  au FileType vim set ts=2 st=2 sw=2 tw=79 et ai 
augroup END
augroup filetype_matlab
  autocmd!
  au FileType matlab set ts=4 st=4 sw=4 tw=79 et ai 
augroup END


" 将路径加入到runtimepath选项中
function! AddToRuntimePath(path)
  let runtimepath = split(&rtp, ',')
  let &rtp = join(insert(runtimepath, a:path), ',')
endfunction

function! SetupPython()
  let system_path = split($PATH, ';')
  let $PATH = join(extend(system_path, [$VIM . '\Python27', $VIM . '\Python35']), ';')
  if !has('python') 
    echom 'Python setup failed!'
  endif
  if !has('python3')
    echom 'Python 3 setup failed!'
  endif
endfunction
augroup vim_start
augroup END
" autocmd vim_start GuiEnter * call SetupPython()

let g:bundle = $VIM . '\bundle'
function! SetupDein()
  let dein_path = g:bundle . '\dein.vim'
  call AddToRuntimePath(dein_path)
  if dein#load_state(g:bundle)
    call dein#begin(g:bundle)
    call dein#add(dein_path)
    for plugin in g:plugin_list
      call dein#add(plugin)
    endfor
    call dein#end()
    call dein#save_state()
  endif
  filetype plugin indent on
  syntax enable
endfunction
" autocmd vim_start GuiEnter * call SetupDein()

function! SetupVundle()
  filetype off
  let vundle_root = g:bundle . '\Vundle.vim'
  call AddToRuntimePath(vundle_root)
  call vundle#begin(g:bundle)
  for plugin in g:plugin_list
    exe 'Plugin ' . plugin
  endfor
  call vundle#end()
	filetype plugin indent on
  syntax enable
endfunction
" autocmd vim_start GuiEnter * call SetupVundle()

function! SetupPlug()
  filetype off
  call AddToRuntimePath(g:bundle . '\vim-plug')
  runtime plug.vim
  call plug#begin(g:bundle)
  for plugin in g:plugin_list
    exe "Plug '" . plugin . "'"
  endfor
  call plug#end()
  filetype plugin indent on
  syntax enable
endfunction
call SetupPlug()

function! SetupVimProc()
	url = 'https://github.com/Shougo/vimproc.vim/releases/download/ver.9.3/vimproc_win64.dll'
endfunction
